﻿using System;

namespace Netbits.Common.Conditions
{
	/// <summary>
	/// Int (32Bit) extensions for validator class
	/// </summary>
	public static partial class ValidatorExtensions
	{
		/// <summary>
		/// Checks if the given value is greater than the specified Value_.
		/// </summary>
		/// <param name="Validator_">The strongly typed validator</param>
		/// <param name="Value_">The highest invalid value</param>
		/// <returns>The Validator if the Value_ is lesser than given value, otherwise ConditionException is thrown</returns>
		/// <exception cref="ConditionException">Thrown if the given value is less than specified Value_</exception>
		public static Validator<int> IsGreaterThan( this Validator<int> Validator_, int Value_ )
		{
			if( Validator_.__Value > Value_ )
				return Validator_;
			throw new ConditionException( "{0} should be greater than {1}", Validator_.GetStringOfValue(), Value_ );
		}

		/// <summary>
		/// Checks if the given value is greater than the specified Value_.
		/// </summary>
		/// <param name="Validator_">The strongly typed validator</param>
		/// <param name="Value_">The highest invalid value</param>
		/// <param name="Message_">The message for the ConditionException</param>
		/// <returns>The Validator if the Value_ is lesser then given value, otherwise ConditionException is thrown</returns>
		/// <exception cref="ConditionException">Thrown if the given value is less than specified Value_</exception>
		public static Validator<int> IsGreaterThan( this Validator<int> Validator_, int Value_, string Message_ )
		{
			if( Validator_.__Value > Value_ )
				return Validator_;
			throw new ConditionException( "{0}{1}{2} should be greater than {3}", Message_, Environment.NewLine, Validator_.GetStringOfValue(), Value_ );
		}

		/// <summary>
		/// Checks if the given value is less than the specified Value_
		/// </summary>
		/// <param name="Validator_">The strongly typed validator</param>
		/// <param name="Value_">The lowest invalid value</param>
		/// <returns>The validator if the Value_ is greater than given value, otherwise ConditionException is thrown</returns>
		/// <exception cref="ConditionException">Thrown if the given value is greater than specified Value_</exception>
		public static Validator<int> IsLessThan( this Validator<int> Validator_, int Value_ )
		{
			if( Validator_.__Value < Value_ )
				return Validator_;
			throw new ConditionException( "{0} should be less than {1}", Validator_.GetStringOfValue(), Value_ );
		}

		/// <summary>
		/// Checks if the given value is less than the specified Value_
		/// </summary>
		/// <param name="Validator_">The strongly typed validator</param>
		/// <param name="Value_">The lowest invalid value</param>
		/// <param name="Message_">The message for the ConditionException</param>
		/// <returns>The Validator if the Value_ is greater than specified Value_</returns>
		/// <exception cref="ConditionException">Thrown if the given value is greater than specified Value_</exception>
		public static Validator<int> IsLessThan( this Validator<int> Validator_, int Value_, string Message_ )
		{
			if( Validator_.__Value < Value_ )
				return Validator_;
			throw new ConditionException( "{0}{1}{2} should be less than {3}", Message_, Environment.NewLine, Validator_.GetStringOfValue(), Value_ );
		}

		/// <summary>
		/// Checks if the given value is equal to the specified Value_
		/// </summary>
		/// <param name="Validator_">The strongly typed validator</param>
		/// <param name="Value_">The value to compare with</param>
		/// <returns>The Validator if the Value_ is equal, otherwise ConditionException is thrown</returns>
		/// <exception cref="ConditionException">Thrown if the given value is NOT equal to the specified Value_</exception>
		public static Validator<int> IsEqualTo( this Validator<int> Validator_, int Value_ )
		{
			if( Validator_.__Value == Value_ )
				return Validator_;
			throw new ConditionException( "{0} should be equal to {1}", Validator_.GetStringOfValue(), Value_ );
		}

		/// <summary>
		/// Checks if the given value is equal to the specified Value_
		/// </summary>
		/// <param name="Validator_">The strongly typed validator</param>
		/// <param name="Value_">The value to compare with</param>
		/// <param name="Message_">The message for the ConditionException</param>
		/// <returns>The Validator if the Value_ is equal, otherwise ConditionExcetion is thrown with specified message.</returns>
		/// <exception cref="ConditionException">Thrown if the given value is NOT equal to the specified Value_</exception>
		public static Validator<int> IsEqualTo( this Validator<int> Validator_, int Value_, string Message_ )
		{
			if( Validator_.__Value == Value_ )
				return Validator_;
			throw new ConditionException( "{0}{1}{2} should be equal to {3}", Message_, Environment.NewLine, Validator_.GetStringOfValue(), Value_ );
		}

		/// <summary>
		/// Checks if the given value is between MinValue_ and MaxValue_
		/// </summary>
		/// <param name="Validator_">The strongly typed validator</param>
		/// <param name="MinValue_">The lowest valid value</param>
		/// <param name="MaxValue_">The highest valid value</param>
		/// <returns>The validator if the Value_ is in range, otherwise ConditionException is thrown</returns>
		/// <exception cref="ConditionException">Thrown if the given value is NOT in range</exception>
		public static Validator<int> IsInRange( this Validator<int> Validator_, int MinValue_, int MaxValue_ )
		{
			if( Validator_.__Value >= MinValue_ && Validator_.__Value <= MaxValue_ )
				return Validator_;
			throw new ConditionException( "{0} should be between {1} and {2}", Validator_.GetStringOfValue(), MinValue_, MaxValue_ );
		}

		/// <summary>
		/// Checks if the given value is between MinValue_ and MaxValue_
		/// </summary>
		/// <param name="Validator_">The strongly typed validator</param>
		/// <param name="MinValue_">The lowest valid value</param>
		/// <param name="MaxValue_">The highest valid value</param>
		/// <param name="Message_">The message for the ConditionException</param>
		/// <returns>The validator if the Value_ is in range, otherwise ConditionException is thrown with specified Value_</returns>
		/// <exception cref="ConditionException">Throw if the given value is NOT in range</exception>
		public static Validator<int> IsInRange( this Validator<int> Validator_, int MinValue_, int MaxValue_, string Message_ )
		{
			if( Validator_.__Value >= MinValue_ && Validator_.__Value <= MaxValue_ )
				return Validator_;
			throw new ConditionException( "{0}{1}{2} should be between {3} and {4}", Message_, Environment.NewLine, Validator_.GetStringOfValue(), MinValue_, MaxValue_ );
		}
	}
}
